package com.fstrat.frontend.webserviceclient;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;

import com.fstrat.backend.entities.Addition;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.core.util.MultivaluedMapImpl;

public class AdditionClient {
	
	public String getSumme(){
		WebResource webResource = WebResourceFactory.getAdditionInstance();
		String summe = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).
									accept(MediaType.TEXT_PLAIN_TYPE).
									get(String.class);
		return summe;
	}
	
	public String getSumme(int zahl1, int zahl2){
		MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
		queryParams.add("zahl1", Integer.toString(zahl1));
		queryParams.add("zahl2", Integer.toString(zahl2));
		WebResource webResource = WebResourceFactory.getAdditionInstance();
		String summe = webResource.path("params")
									.queryParams(queryParams)
									.accept(MediaType.TEXT_PLAIN_TYPE)
									.get(String.class);
		return summe;
	}
	
	public String getJSON(int zahl1, int zahl2, int zahl3){
		MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
		queryParams.add("zahl1", Integer.toString(zahl1));
		queryParams.add("zahl2", Integer.toString(zahl2));
		queryParams.add("zahl3", Integer.toString(zahl3));
		WebResource webResource = WebResourceFactory.getAdditionInstance();
		String summe = webResource.path("addtionJSON").queryParams(queryParams)
									.accept(MediaType.APPLICATION_JSON_TYPE)
									.get(String.class);
		return summe;
	}
	
	public String getTotalJSON(int zahl1, int zahl2, int zahl3){
		WebResource webResource = WebResourceFactory.getAdditionInstance();
		Addition additionParam = new Addition();
		additionParam.setZahl1(zahl1);
		additionParam.setZahl2(zahl2);
		additionParam.setZahl3(zahl3);
		Addition summe = webResource.type(MediaType.APPLICATION_JSON_TYPE)
									.accept(MediaType.APPLICATION_JSON_TYPE)
									.post(Addition.class, additionParam);
		return Integer.toString(summe.getErgebnis());
	}
}
